import {config} from "@/config";

const uniRequest = (method, url, data = {}, header = {}) => {
    const baseUrl = config.baseUrl;
    const requestUrl = baseUrl + url;
    const sessionKey = uni.getStorageSync('sessionKey');
    if (sessionKey) {
        header = {
            'sessionKey': sessionKey,
            ...header,
        };
    }
    return new Promise((resolve, reject) => {
        uni.request({
            url: requestUrl,
            method: method,

            data: data,
            header: {
                'content-type': 'application/json',
                ...header
            },
            success: res => {
                resolve(res.data)
            },
            fail: err => {
                reject(err)
            }
        })
    })
};
export const get = (url, params = {}, header = {}, body) => {
    return uniRequest('GET', url, params, header)
};
export const post = (url, data = {}, header = {}, body) => {
    return uniRequest('POST', url, data, header)
};